﻿@model OT.Areas.Admin.Models.Subjects
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
    <h3 id="myModalLabel">Create Subject</h3>
</div>
<div class="modal-body">
    <div id="alert_modal">
        @Html.ValidationSummary()
    </div>
    <div class="form-horizontal" role="form">
        <div class="form-group">
            <div class="col-lg-15">
                <div id="divMsgCre"></div>
            </div>
        </div>
        <div class="form-group" id="divCategoryName">
            <label class="col-lg-3 control-label">Category Name</label>
            <div class="col-lg-5">
                @Html.DropDownListFor(model => model.CategoryID, new SelectList(Model.categorys, "CategoryID", "CategoryName"), "--select--", new { @class = "form-control", id = "CategoryID" })
                @Html.ValidationMessageFor(model => model.CategoryID)
            </div>
        </div>
        <div class="form-group" id="divSubjectName">
            <label class="col-lg-3 control-label">Subject Name</label>
            <div class="col-lg-5">
                <input class="form-control" type="text" placeholder="Enter Subject Name" id="SubjectName" maxlength="20">
            </div>
        </div>
        <div class="form-group" id="divDescription">
            <label class="col-lg-3 control-label">Description</label>
            <div class="col-lg-5">
                <textarea class="form-control" placeholder="Enter Description" id="Description" rows="3" maxlength="50"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-lg-3 control-label">Status</label>
            <div class="col-lg-1">
                <input class="form-control" id="st" name="st" type="checkbox">
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-default" type="submit" id="btnCreate"><i class="icon-cog"></i>Save</button>
    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="icon-off"></i>Cancel</button>
</div>
<script type="text/javascript">
    $("#btnCreate").click(function (e) {
        var SubjectName = $("#SubjectName").val();
        var Description = $("#Description").val();
        var CategoryID = $("#CategoryID").val();
        if ($("#st").is(':checked')) {
            Status = true;
        }
        else {
            Status = false;
        }
        e.preventDefault();
        if (SubjectName == '' || CategoryID == 0) {
            showMsg('divMsgCre', 'Please Enter Value For Required Fields', 'danger');
            (CategoryID == 0) ? $('#divCategoryName').addClass('has-error') : $('#divCategoryName').removeClass('has-error');
            (SubjectName == '') ? $('#divSubjectName').addClass('has-error') : $('#divSubjectName').removeClass('has-error');
        }
        else {
            $.ajax({
                url: "/Admin/Subject/Create?SubjectName=" + SubjectName + "&Description=" + Description + "&Status=" + Status + "&CategoryID=" + CategoryID,
                type: "POST",
                success: function (result) {
                    if (result != "NotValid") {
                        $('#modalDiv').modal('hide');
                        showMsg('divMsgIndex', ' Record saved Sucessfully .', 'success');
                        loadPage(1, 10, '');
                    }
                    else {
                        showMsg('divMsgCre', 'Record Not Saved', 'danger');
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
    });
</script>
